package com.titan.travelagent;

import javax.annotation.Resource;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Message;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;

@MessageDriven(activationConfig = {
		@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
		@ActivationConfigProperty(propertyName = "destination", propertyValue = "TestTopic1"),
		@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") })
public class TestTopicBean1 implements javax.jms.MessageListener {

	@Resource(mappedName = "MyJmsConnectionFactory")
	ConnectionFactory jmsConnectionFactory;
	
	@Resource(mappedName = "Response")
	Queue queue;
	
	public void onMessage(Message message) {
		try {
			System.out.println("I'm onMessage TestTopicBean1");
			Connection connection = jmsConnectionFactory.createConnection();
		    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
		    MessageProducer sender = session.createProducer(queue);
		    message = session.createTextMessage("TestTopic1");
		    sender.send(message);
		    session.close();
		    connection.close();
		} catch (Exception ex) {
		}
	}
}
